//
//  LeverCollectionViewCell.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/5/23.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit
protocol leverCellDelegate:class {
    func changeNumber(index:Int,addBool:Bool)
}
class LeverCollectionViewCell: BaseCollectionViewCell {
    var index:Int? //标记第几个cell
    lazy var minusBtn:CustomBtn = {
        let btn = CustomBtn(style: placeStyle.styleLeft)
        btn.addTarget(self, action: #selector(minusBtnAction), for: UIControlEvents.touchUpInside)
        btn.photoImageView.image = UIImage(named: "leverMinus")
        return btn
    }()
    
    lazy var writextField:BaseTextField = {
       let textfield = BaseTextField(changeView: nil, szBounds: CGRect.zero)
        textfield.textAlignment = NSTextAlignment.center
        textfield.keyboardType = .decimalPad
       return textfield
    }()
    
    lazy var addBtn:CustomBtn = {
        let btn = CustomBtn(style: placeStyle.styleLeft)
        btn.addTarget(self, action: #selector(addBtnAction), for: UIControlEvents.touchUpInside)
        btn.photoImageView.image = UIImage(named: "leverAdd")
        return btn
    }()
    
    weak var delegate:leverCellDelegate?
    
   override func setUpUI() {
      self.contentView.addSubview(minusBtn)
      minusBtn.photoImageView.snp.makeConstraints { (make) in
        make.left.centerY.equalToSuperview()
      }
       minusBtn.snp.makeConstraints { (make) in
        make.left.equalToSuperview()
        make.top.bottom.equalToSuperview()
        make.width.equalTo(30)
     }
    
     self.contentView.addSubview(writextField)
     writextField.snp.makeConstraints { (make) in
        make.top.bottom.equalToSuperview()
        make.left.equalToSuperview().offset(30)
        make.right.equalToSuperview().offset(-30)
     }
    self.contentView.addSubview(addBtn)
    addBtn.photoImageView.snp.makeConstraints { (make) in
        make.right.centerY.equalToSuperview()
    }
    addBtn.snp.makeConstraints { (make) in
        make.right.equalToSuperview()
        make.top.bottom.equalToSuperview()
        make.width.equalTo(30)
    }
   }
    
    @objc func addBtnAction() {
        if delegate != nil && delegate?.changeNumber != nil {
            self.delegate?.changeNumber(index: index!, addBool: true)
        }
    }
    
    @objc func minusBtnAction() {
        if delegate != nil && delegate?.changeNumber != nil {
            self.delegate?.changeNumber(index: index!, addBool: false)
        }
    }
}
